﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Runtime.InteropServices;

namespace dreametryVersion2
{
    class global
    {
        public static String conString = ConfigurationManager.ConnectionStrings["dreametryVersion2.Properties.Settings.DreametryDBConnectionString"].ConnectionString;
        public static String employeeID;
        public static String fullname;
        public static String folder;
        public static String themeColor;
        public static byte[] picture;

        public static String CalculateMD5Hash(string input)
        {
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }

        public static MemoryStream getEmployeePicture(object picture)
        {
            byte[] image = (byte[])picture;
            MemoryStream stream = new MemoryStream(image);

            return stream;
        }

        public static String darkerColor(String color)
        {
            //declare variables
            String finalColor;
            String[] values = new String[] {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
            //remove # from string
            String newColor = color.Replace("#","").ToUpper();
            String scolor = newColor;
            //extract theme color to array
            String[] arrColor = scolor.Select(c => c.ToString()).ToArray();
            //reduce value of theme color
            List<String> fragmentColor = new List<String>();

            for(int x=0; x < arrColor.Length; x++)
            {
                for(int y=0; y < values.Length; y++)
                {
                    if(arrColor[x] == values[y])
                    {
                        try
                        {
                            fragmentColor.Add(values[y - 2]);
                        }
                        catch
                        {
                            fragmentColor.Add(values[y]);
                        }
                     }
                }
            }

            finalColor = "#" + string.Join("", fragmentColor.ToArray());
            return finalColor;
        }

        public static String lighterColor(String color)
        {
            //declare variables
            String finalColor;
            String[] values = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
            //remove # from string
            String newColor = color.Replace("#", "").ToUpper();
            String scolor = newColor;
            //extract theme color to array
            String[] arrColor = scolor.Select(c => c.ToString()).ToArray();
            //reduce value of theme color
            List<String> fragmentColor = new List<String>();

            for (int x = 0; x < arrColor.Length; x++)
            {
                for (int y = 0; y < values.Length; y++)
                {
                    if (arrColor[x] == values[y])
                    {
                        try
                        {
                            fragmentColor.Add(values[y + 3]);
                        }
                        catch
                        {
                            fragmentColor.Add("F");
                        }
                    }
                }
            }

            finalColor = "#" + string.Join("", fragmentColor.ToArray());
            return finalColor;
        }
    }
}
